package org.mspring.platform.changyan;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.client.utils.URIBuilder;

/**
 * 畅言OpenAuth服务
 *
 * @author Gao Youbo
 * @since 2014-05-26 19:03:56
 */
public class ChangyanOAuthService {

    public void authorize() throws URISyntaxException {
        Map<String, String> params = new HashMap<>();
        params.put("client_id", ChangyanConstants.APPID);
        params.put("redirect_uri", "http://www.mspring.org");
        params.put("response_type", "code");
//        StringBuilder url = new StringBuilder();
//        url.append("https://changyan.sohu.com/api/oauth2/authorize");
        URIBuilder builder = new URIBuilder("https://changyan.sohu.com/api/oauth2/authorize");
        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder.addParameter(entry.getKey(), entry.getValue());
        }
        URI uri = builder.build();
        System.out.println(uri.toString());
    }

    public static void main(String[] args) throws URISyntaxException {
        new ChangyanOAuthService().authorize();
    }
}
